home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / tex / lgrind.zoo / v2lg.c < prev    next >
C/C++ Source or Header  |  1992-09-28  |  2KB  |  79 lines

  1. /*
  2.  * Filter a LaTeX file into an lgrind file.  Convert
  3.  * \begin{verbatim}-\end{verbatim} pairs into %[ - %] pairs.  Tabify
  4.  * the former verbatim environments. Convert \verb|stuff| into @stuff@.
  5.  */
  6.  
  7. #ifndef lint
  8. static char Version[] =
  9.    "$Id: v2lg.c,v 1.1 91/10/01 00:44:22 gvr Exp $";
  10. #endif
  11.  
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. #define FALSE    0
  17. #define TRUE    1
  18.  
  19. #define STREQ(s,t)  ((*(s) == *(t)) && (!*(s) || !strcmp((s),(t))))
  20.  
  21.  
  22. main(argc, argv)
  23.    int    argc;
  24.    char    **argv;
  25. {
  26.    int in_verbatim = FALSE, col, start_col;
  27.    char in[256], out[256], *ic, *oc, *verb, delim;
  28.  
  29.    while (fgets(in, sizeof(in), stdin) != NULL) {
  30.       if (in_verbatim) {
  31.      if (STREQ(in, "\\end{verbatim}\n")) {
  32.         fputs("%]\n", stdout);
  33.         in_verbatim = FALSE;
  34.         continue;
  35.      }
  36.      for (col = 0, ic = in, oc = out; *ic != '\n'; ) {
  37.         if (*ic != ' ' && *ic != '\t') {
  38.            *oc++ = *ic++; col++;
  39.         } else {    /* \t == ' ' in a verbatim environment */
  40.            start_col = col;
  41.            while (*ic == ' ' || *ic == '\t') {
  42.           if (((++col) & 7) == 0) {
  43.              *oc++ = '\t'; start_col = col;
  44.           }
  45.           ic++;
  46.            }
  47.            if ((col & 7) != 0)
  48.           for ( ; start_col < col; start_col++)
  49.              *oc++ = ' ';
  50.         }
  51.      }
  52.      *oc++ = '\n'; *oc++ = '\0';
  53.      fputs(out, stdout);
  54.      continue;
  55.       }
  56.       if (STREQ(in, "\\begin{verbatim}\n")) {
  57.      fputs("%[\n", stdout);
  58.      in_verbatim = TRUE;
  59.      continue;
  60.       }
  61.       for (ic = in; (verb = strstr(ic, "\\verb")) != NULL; ) {
  62.      for ( ; ic < verb; ic++)
  63.         putchar(*ic);
  64.      ic += 5;        /* Skip over \verb */
  65.      if (*ic == '*')    /* \verb* => funny-looking spaces */
  66.         ic++;
  67.      delim = *ic++;        /* the delimiter char */
  68.      putchar('@');
  69.      while (*ic != delim) {
  70.         putchar(*ic); ic++;
  71.      }
  72.      ic++;            /* Skip the other delimiter */
  73.      putchar('@');
  74.       }
  75.       fputs(ic, stdout);
  76.    }
  77. }
  78.  
  79.